<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css"
          integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
            integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
            crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
            integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
            crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js"
            integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
            crossorigin="anonymous"></script>
    <style>
        .login a {
            color: #fff;
            font-weight: 500;
        }
        .login a:hover{
            color: #fff;
        }
        a:hover{
            text-decoration:none;
            }
    </style>
</head>
<body>
    <!-- 如果未登录 -->
    <!-- Security 的登录链接: /toLogin （必须这么写）-->
    <div sec:authorize="!isAuthenticated()" class="login">
        <button type="button" class="btn btn-primary"><a th:href="@{/toLogin}">登录</a></button>
    </div>

    <!-- 如果已登录 显示用户名、注销 -->
    <!-- Security 的退出链接: /logout （必须这么写）-->
    <div sec:authorize="isAuthenticated()" class="login">
        用户名：<span sec:authentication="name"></span>
        <button type="button" class="btn btn-danger"><a th:href="@{/logout}">注销</a></button>
    </div>

    <!-- 菜单根据用户的角色动态实现 -->

    <div sec:authorize="hasAuthority('MYUSER_VIEW')">
        <a th:href="@{/myuser/select}">用户管理</a>
    </div>
    <br>
    <div sec:authorize="hasAuthority('ROLE_VIEW')">
        <a th:href="@{/role/select}">角色管理</a>
    </div>
    <br>
    <div sec:authorize="hasAuthority('AUTHORITY_VIEW')">
        <a th:href="@{/authority/select}">权限管理</a>
    </div>
</body>
</html>